package com.byd.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;

@Configuration
public class MailConfig {

    @Bean
    public JavaMailSender getJavaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.126.com"); // 设置SMTP服务器地址
        mailSender.setPort(25); // 设置SMTP服务器端口，默认为25，也可以设置为465或587等
        mailSender.setUsername("hewei090918@126.com"); // 设置发送邮件的邮箱地址
        mailSender.setPassword("DHeJhWCJ5QkyTU7S"); // 设置邮箱密码或授权码

        Properties props = mailSender.getJavaMailProperties();
        props.put("mail.transport.protocol", "smtp"); // 设置传输协议
        props.put("mail.smtp.auth", "true"); // 启用认证
        props.put("mail.smtp.starttls.enable", "true"); // 启用STARTTLS
        // 可以根据需要设置更多属性，如SSL等
        return mailSender;
    }
}
